package com.dm.library.http;


import android.content.Context;
import android.text.TextUtils;

import com.dm.library.utils.DMCache;

/**
 * 版 权: 深圳市迪蒙网络科技有限公司
 * 描 述: <描述>
 * 修 改 人: sushuo
 * 修改时间: 2016-12-3
 */
public class TokenManager {

    /**
     * token
     */
    private String token;
    private String deviceToken;

    private static TokenManager mTokenManager = null;

    public static TokenManager getInstance() {
        if (mTokenManager == null) {
            mTokenManager = new TokenManager();
        }
        return mTokenManager;

    }

    public String getToken(Context context) {
        if (TextUtils.isEmpty(token)) {
            DMCache dmCache = DMCache.get(context);
            token = dmCache.getAsString("Authorization");
        }
        return token;
    }

    public void setToken(Context context, String token) {
        DMCache dmCache = DMCache.get(context);
        dmCache.put("Authorization", token);
        this.token = token;
    }

    public void removeToken(Context context) {
        DMCache dmCache = DMCache.get(context);
        dmCache.remove("Authorization");
        this.token = null;
    }


    /***
     * 设置友盟推送 DeviceToken
     * @param context
     * @param token
     */
    public void setDeviceToken(Context context, String token) {
        DMCache dmCache = DMCache.get(context);
        dmCache.put("deviceToken", token);
        this.deviceToken = token;
    }

    /***
     * 获取友盟推送 DeviceToken
     * @param context
     * @return
     */
    public String getDeviceToken(Context context) {
        if (TextUtils.isEmpty(deviceToken)) {
            DMCache dmCache = DMCache.get(context);
            deviceToken = dmCache.getAsString("deviceToken");
        }
        return deviceToken;
    }

    /***
     * 移除友盟推送 DeviceToken
     * @param context
     */
    public void removeDeviceToken(Context context) {
        DMCache dmCache = DMCache.get(context);
        dmCache.remove("deviceToken");
        this.deviceToken = null;
    }



}
